<template>
	<view class="page-content">
		<view class="page-top">
			<!-- 标题栏和状态栏占位符 -->
			<view class="titleNview-placing"></view>
			<w-sel-search topType="two" leftIcon="arrowleft" iconfont="28" @resetFilterData="resetFilterData"
				@setFilterData="setFilterData">
			</w-sel-search>
			<!--导航-->
			<view class="nav">
				<view class="nav-item" @click="handleActive(1)"
					:class="[active === 1 ? 'active' : active === 2 ? '' : active === 3 ? '' :'']">
					进行中<view class="nav-item-num" v-if="ld_num > 0 ? true:false">{{ld_num}}</view>
				</view>
				<view class="nav-item" @click="handleActive(2)"
					:class="[active === 1 ? '' : active === 2 ? 'active' : active === 3 ? '' :'']">
					待审批<view class="nav-item-num" v-if="cy_num > 0 ? true:false">{{cy_num}}</view>
				</view>
				<view class="nav-item" @click="handleActive(3)"
					:class="[active === 1 ? '' : active === 2 ? '' : active === 3 ? 'active' :'']">
					已审批
				</view>
				<view class="nav-item" @click="handleActive(4)"
					:class="[active === 1 ? '' : active === 2 ? '' : active === 3 ? '' :'active']">
					我的下单
				</view>
			</view>
		</view>
		<!--我的工作-->
		<scroll-view class="page-body" :scroll-top="scrollTop" scroll-y="true" @scrolltolower="loadmore()">
			<!--进行中-->
			<view class="body-item" v-if="active=== 1">
				<template v-if="datalist1 && datalist1.length > 0 ">
					<block v-for="(item,index) in datalist1" :key="index">
						<view class="item-box">
							<work-statu :obj="item" page_type="1" @todetail="todetail"></work-statu>
						</view>
					</block>
					<!-- 上拉加载 -->
					<view class="det-con-more">
						<load-more :loadmore="load_more1"></load-more>
					</view>
				</template>
				<!--无数据-->
				<empty v-else no-full type="noData" bgcolor="#f5f5f5"></empty>
			</view>

			<!--待审批-->
			<view class="body-item" v-if="active === 2">
				<template v-if="datalist2 && datalist2.length > 0 ">
					<block v-for="(item,index) in datalist2" :key="index">
						<view class="item-box">
							<work-statu :obj="item" page_type="2" @todes="todes" @todetail="todetail"></work-statu>
						</view>
					</block>
					<!-- 上拉加载 -->
					<view class="det-con-more">
						<load-more :loadmore="load_more2"></load-more>
					</view>
				</template>
				<!--无数据-->
				<empty v-else no-full type="noData" bgcolor="#f5f5f5"></empty>
			</view>

			<!--已审批-->
			<view class="body-item" v-if="active === 3">
				<template v-if="datalist3 && datalist3.length > 0 ">
					<block v-for="(item,index) in datalist3" :key="index">
						<view class="item-box">
							<work-statu :obj="item" page_type="3" @todetail="todetail"></work-statu>
						</view>

					</block>
					<!-- 上拉加载 -->
					<view class="det-con-more">
						<load-more :loadmore="load_more3"></load-more>
					</view>
				</template>
				<!--无数据-->
				<empty v-else no-full type="noData" bgcolor="#f5f5f5"></empty>
			</view>

			<!--我的下单-->
			<view class="body-item" v-if="active === 4">
				<template v-if="datalist4 && datalist4.length > 0 ">
					<block v-for="(item,index) in datalist4" :key="index">
						<view class="item-box">
							<work-statu :obj="item" page_type="4" @todetail="todetail"></work-statu>
						</view>

					</block>
					<!-- 上拉加载 -->
					<view class="det-con-more">
						<load-more :loadmore="load_more4"></load-more>
					</view>
				</template>
				<!--无数据-->
				<empty v-else no-full type="noData" bgcolor="#f5f5f5"></empty>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		mapMutations,
		mapState
	} from 'vuex'
	import wSelSearch from '@/components/w-sel-logo/w-sel-search.vue'; //搜索
	import loadMore from '@/components/uni-load-more/load-more.vue'; //加载更多
	import workStatu from '@/pages/components/work_statu.vue'; //工作动态
	import {
		getgamelists,
		getuserawaitlists, //获取待开赛比赛列表【我的】
	} from '@/common/api.js'
	export default {
		components: {
			loadMore,
			wSelSearch,
			workStatu
		},
		data() {
			return {
				scrollTop: 0,
				noData: false,
				load_more1: '', //下拉加载文字
				load_more2: '', //下拉加载文字
				load_more3: '', //下拉加载文字
				load_more4: '', //下拉加载文字
				load_sta: false, //是否是加载状态
				active: 1, //tab导航
				lists: [],
				datalist1: [{
					title: '厦门市体育路八号店铺厦门市体育路八号店铺',
					taskname: '这是任务名这是任务名这是任务名这是任务名这是任务名',
					name: '刘星刘星刘星刘星刘星刘星',
					time: '2020-11-11',
					remack: '打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包',
					money: '999',
					statu: 1, // 1-已完成、已读  2-进行中、未读
					type: 1, // 1-道具   2-POP  3-
				}, {
					title: '厦门市体育路八号店铺厦门市体育路八号店铺',
					taskname: '这是任务名这是任务名这是任务名这是任务名这是任务名',
					name: '刘星刘星刘星刘星刘星刘星',
					time: '2020-11-11',
					remack: '打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包',
					money: '999',
					statu: 1, // 1-已完成、已读  2-进行中、未读
					type: 2, // 1-道具   2-POP  3-
				}],
				datalist2: [{
					title: '厦门市体育路八号店铺厦门市体育路八号店铺',
					taskname: '这是任务名这是任务名这是任务名这是任务名这是任务名',
					name: '刘星刘星刘星刘星刘星刘星',
					time: '2020-11-11',
					remack: '打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包',
					money: '999',
					statu: 2, // 1-已完成、已读  2-进行中、未读
					type: 2, // 1-道具   2-POP  3-
					user:{
						name:'啊实打实',
						head:'/static/data-img/data-tx.png'
					},
					is_last:false //是否最后一个
				}, {
					title: '厦门市体育路八号店铺厦门市体育路八号店铺',
					taskname: '这是任务名这是任务名这是任务名这是任务名这是任务名',
					name: '刘星刘星刘星刘星刘星刘星',
					time: '2020-11-11',
					remack: '打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包',
					money: '999',
					statu: 1, // 1-已完成、已读  2-进行中、未读
					type: 1, // 1-道具   2-POP  3-
					user:{
						name:'',
						head:''
					},
					is_last:true //是否最后一个
				}],
				datalist3: [{
					title: '厦门市体育路八号店铺厦门市体育路八号店铺',
					taskname: '这是任务名这是任务名这是任务名这是任务名这是任务名',
					name: '刘星刘星刘星刘星刘星刘星',
					time: '2020-11-11',
					remack: '打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包',
					money: '999',
					statu: 1, // 1-已完成、已读  2-进行中、未读
					type: 1, // 1-道具   2-POP  3-
				}, {
					title: '厦门市体育路八号店铺厦门市体育路八号店铺',
					taskname: '这是任务名这是任务名这是任务名这是任务名这是任务名',
					name: '刘星刘星刘星刘星刘星刘星',
					time: '2020-11-11',
					remack: '打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包',
					money: '999',
					statu: 1, // 1-已完成、已读  2-进行中、未读
					type: 1, // 1-道具   2-POP  3-
				}],
				datalist4: [{
					title: '1厦门市体育路八号店铺厦门市体育路八号店铺',
					taskname: '这是任务名这是任务名这是任务名这是任务名这是任务名',
					name: '刘星刘星刘星刘星刘星刘星',
					time: '2020-11-11',
					remack: '打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包',
					money: '999',
					statu: 1, // 1-已完成、已读  2-进行中、未读
					type: 1, // 1-道具   2-POP  3-
				}, {
					title: '2厦门市体育路八号店铺厦门市体育路八号店铺',
					taskname: '这是任务名这是任务名这是任务名这是任务名这是任务名',
					name: '刘星刘星刘星刘星刘星刘星',
					time: '2020-11-11',
					remack: '打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包打包画册时请注意不要有破碎，仔细检查，打包时按10本一套来打包',
					money: '999',
					statu: 1, // 1-已完成、已读  2-进行中、未读
					type: 1, // 1-道具   2-POP  3-
				}],
				code: '',
				formData1: {
					page: 1,
					limit: 10,
					type: '1'
				},
				formData2: {
					page: 1,
					limit: 10,
					type: '2'
				},
				ld_num: 3,
				cy_num: 2,
				is_show: false
			}
		},
		computed: {
			...mapState(['hasLogin', 'openid'])
		},
		onShow() {
			this.getdata1(this.formData1);
			this.getdata2(this.formData2);
		},
		onLoad(option) {
			console.log(222, option)
			if (option.active) {
				this.active = parseInt(option.active);
				console.log(3,this.active)
			}
		},
		onNavigationBarButtonTap(e) {
			console.log(123, e)
			if (e.index === 0) {
				console.log(444, this.is_show)

				this.is_show = true
				console.log(444, this.is_show)
			}
		},
		onNavigationBarSearchInputClicked(e) {
			console.log('点击了搜索框')
		},
		onNavigationBarSearchInputChanged(e) {
			console.log(e.text) //打印输入框值
		},
		//监听原生标题栏搜索输入框搜索事件，用户点击软键盘上的“搜索”按钮时触发。
		onNavigationBarSearchInputConfirmed(e) {
			console.log(e.text) //打印输入框值
		},
		methods: {
			todetail(id){
				uni.navigateTo({
					url: `/pages/work/workDetail?id=${id}`
				})
			},
			//跳转指派
			todes(id){
				uni.navigateTo({
					url: `/pages/designate/des_one?id=${id}`
				})
			},
			//重置筛选
			resetFilterData() {

			},
			//确认筛选
			setFilterData() {

			},
			//下拉加载
			loadmore() {
				console.log('下拉加载');
				let _self = this;
				_self.load_sta = true;
				if (_self.active === 1) {
					_self.formData1.page++;
					_self.getdata1(_self.formData1);
				} else if (_self.active === 2) {
					_self.formData2.page++;
					_self.getdata2(_self.formData2);
				}
			},

			//获取当前比赛数据
			getdata1(formData) {
				console.log(234, formData)
				/* getuserawaitlists(formData).then(res => {
					console.log(123, res)
					this.ld_num = res.count
					let datalist = res.data
					if(datalist && datalist.length>0){
						datalist.forEach(item => {
							this.$set(item, 'image', item.img[0])
						})
						if(this.load_sta){
							if (datalist && datalist.length < 10) {
								this.load_more1 = '没有更多了';
								this.datalist1 = this.datalist1.concat(datalist);
							} else {
								this.load_more1 = '加载中...';
									this.datalist1 = this.datalist1.concat(datalist);
							}
						}else{
							if (datalist && datalist.length < 10) {
								this.load_more1 = '没有更多了';
								this.datalist1 = datalist;
							} else {
								this.load_more1 = '加载中...';
								this.datalist1 = datalist;
							}
						}
					}
				}) */
			},
			//获取往期回顾数据
			getdata2(formData) {
				/* getuserawaitlists(formData).then(res => {
					console.log(123, res)
					this.cy_num = res.count
					let datalist = res.data
					if(datalist && datalist.length>0){
						datalist.forEach(item => {
							this.$set(item, 'image', item.img[0])
						})
						if(this.load_sta){
							if (datalist && datalist.length < 10) {
								this.load_more2 = '没有更多了';
								this.datalist2 = this.datalist2.concat(datalist);
							} else {
								this.load_more2 = '加载中...';
									this.datalist2 = this.datalist2.concat(datalist);
							}
						}else{
							if (datalist && datalist.length < 10) {
								this.load_more2 = '没有更多了';
								this.datalist2 = datalist;
							} else {
								this.load_more2 = '加载中...';
								this.datalist2 = datalist;
							}
						}
					}
				}) */
			},
			change(e) {
				this.current = e.detail.current
			},
			handleActive(e) {
				let _self = this;
				_self.active = e;
				_self.load_sta = false;
				if (_self.active === 1) {
					_self.formData1.type = '1'
					_self.getdata1(_self.formData1);
				}
				if (_self.active === 2) {
					_self.formData2.type = '2'
					_self.getdata2(_self.formData2);
				}
			},
		},
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
			/* if (this.$refs.indexPage) {
				this.$refs.indexPage.getData()
				console.log(1231)
			} */
		}
	}
</script>

<style lang="scss">
	.titleNview-placing {
		height: var(--status-bar-height);
		box-sizing: content-box;
		background: $uni-bg-color;
		display: block;
		position: sticky;
		top: 0rpx;
		z-index: 9999;
		overflow: hidden
	}
	.page-content {
		display: flex;
		flex-direction: column;
		height: 100%;

		.page-top {
			display: flex;
			flex-direction: column;
			box-sizing: content-box;
			background: $uni-bg-color;
			display: block;
			position: sticky;
			top: 0rpx;
			z-index: 9999;

			.nav {
				height: 80rpx;
				padding: 0 30rpx;
				display: flex;
				align-items: center;
				text-align: center;
				font-size: 28rpx;
				color: $font-color-3;

				.nav-item {
					flex: 1;
					position: relative;

					&::after {
						content: '';
						width: 0;
						height: 8rpx;
						background-color: $font-color-b3;
						border-radius: 4px;
						position: absolute;
						left: 50%;
						bottom: -18rpx;
						transform: translateX(-50%);
						transition: .3s;
					}

					&.active {
						font-size: 32rpx;
						font-weight: bold;
						color: $font-color-b3;

						&::after {
							width: 36rpx;
						}
					}

					.nav-item-num {
						position: absolute;
						right: 0;
						top: -6rpx;
						width: 32rpx;
						height: 32rpx;
						background: #FF5454;
						border-radius: 50%;
						font-size: 18rpx;
						font-weight: 400;
						line-height: 30rpx;
						color: $font-color-w;
					}
				}
			}
		}

		.page-body {
			height: calc(100% - 170rpx);
			background: $uni-bg-color-grey;

			.body-item {
				padding-top: 30rpx;
				display: flex;
				flex-direction: column;
				height: 100%;

				.item-box {
					display: flex;
					margin: 0 30rpx 30rpx 30rpx;
					background: $uni-bg-color;
					box-shadow: 6rpx 6rpx 20rpx rgba(181, 181, 181, 0.14);
					border-radius: 10rpx;
				}
			}
		}

	}

	.det-con-more {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-bottom: 10rpx;
		color: #bbb;
		font-size: 24rpx;
	}

	.index-header {
		display: flex;
		flex-direction: column;
		width: 100%;
		height: 70rpx;
		background-color: #f5f5f5;
		position: relative;


	}
</style>
